// Shell.

#include "types.h"
#include "user.h"

int
main(void)
{
  static char buf[100];
  int i;
  // Read and run input commands.
  while(1){
    printf(1, "mysh35@ ");
    memset(buf, 0, 100);
    gets(buf,100);
    i=strlen(buf);
    if(i<=1){
        //empty line
        continue;
    }
    buf[i-1]=0;
    if(strcmp(buf,"quit")==0){
        //exit command
        break;
    }
    if(strcmp(buf,"promise")==0){//promise command
        printf(1,"I am Xiaojun. I will study OS hard.\n");
        continue;
    }

    //other commands
    if(strcmp(buf,"ls")==0||strcmp(buf,"sh")==0||strcmp(buf,"mysh35")==0){
        //ls,sh,mysh35 command
        if(fork() == 0){
            char *argv[2];
            argv[0] = buf;
            argv[1] = 0;
            exec(buf, argv);
        }           
        wait();
        continue;
    }  

    //unrecognized commands
    printf(1,"mysh35: command not found: %s\n",buf);
  }
  exit();
}

